package com.mzj.saas.mservice.community.repository;

import com.mzj.saas.mservice.community.entity.HouseSurrender;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.math.BigDecimal;
import java.util.List;

public interface HouseSurrenderRepository extends PagingAndSortingRepository<HouseSurrender, Long>, JpaSpecificationExecutor<HouseSurrender> {
    @Modifying
    @Query(value = "UPDATE m_house_surrender SET house_status = ?1,damage_reason = ?2 WHERE id =?3 AND house_id = ?4", nativeQuery = true)
    Integer updateHouseStatusAndDamageReasonByIdAndHouseId(Integer houseStatus, String damageReason, Long id, String houseId);

    @Modifying
    @Query(value = "UPDATE m_house_surrender SET status = ?1,end_time = now()  WHERE id =?2 AND house_id = ?3", nativeQuery = true)
    Integer updateStatusByIdAndHouseId(Integer status, Long id, String houseId);

    @Modifying
    @Query(value = "UPDATE m_house_surrender SET unpaid_amount = ?1,rent_amount = ?2,cash_pledge_amount = ?3,other_amount = ?4,settlement_amount = ?5, bill_id = ?6,status =3 WHERE id = ?7", nativeQuery = true)
    Integer updatemoney(BigDecimal unpaidAmount, BigDecimal rentAmount, BigDecimal cashPledgeAmount, BigDecimal otherAmount, BigDecimal settlementAmount, Long billId, Long id);

    List<HouseSurrender> findByHouseId(String houseId);

    HouseSurrender findByIdAndHouseId(Long id, String houseId);

    @Modifying
    @Query(value = "UPDATE m_house_surrender SET status = ?1,end_time = now()  WHERE id =?2 AND house_id = ?3", nativeQuery = true)
    Integer updateStatusfinsh(Integer status, Long id, String houseId);

    /**
     * 支付完成
     *
     * @param status
     * @param id
     * @param houseId
     * @return
     * @author shun
     * @date 2022年7月6日
     */
    @Modifying
    @Query(value = "UPDATE m_house_surrender SET status = ?1,end_time = now()  WHERE bill_id =?2 AND house_id = ?3 AND status = 3 ", nativeQuery = true)
    Integer updatePayFinshStatus(Integer status, Long billd, String houseId);
}
